%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<%
options(digits = 3) 
# careful do not use & as it is protected by latex
# n_col = 5
# r_dp_bubble_list <- list(r1 = r_sm_p_1a, r2 = r_sm_p_2a, r4 = r_sm_p_4a, 
#                          r5 = r_sm_f_1a, r6 = r_sm_f_2a, r8 = r_sm_f_4a)
%>

% PANEL A:
% SC on unemployment, income, DTI and Debt
% r_brew_list1 <- list(reg1b_unemp2, reg2b_unemp2, reg1b_inc, reg2b_inc)
% r_brew_list2 <- list(reg1b_dti, reg2b_dti, reg1b_debt, reg2b_debt)
% r_brew_list3 <- list(reg1b_debt, reg2b_debt, reg1b_mort, reg2b_mort, reg1b_other, reg2b_other, reg1b_car, reg2b_car)
% r_brew_list4 <- list(reg3_iv_debt, reg3b_iv_debt, reg4_iv_debt, reg4b_iv_debt, reg5b_iv1_debt, reg5_iv1_debt, reg5b_iv2_debt, reg5_iv2_debt)
% r_brew_list5 <- list(reg3_iv_dti, reg3b_iv_dti, reg4_iv_dti, reg4b_iv_dti, reg5_iv1_dti, reg5b_iv1_dti, reg5_iv2_dti, reg5b_iv2_dti)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tabular*}{1.0\textwidth}{@{}l@{\extracolsep{\fill}}ccc ccc@{}}

\toprule

\addlinespace

% Set up the first
 & 
 \multicolumn{3}{c}{\textbf{} Patent Level} &
 \multicolumn{3}{c}{\textbf{} Firm Level}   \\

 \cmidrule[0.5pt](l{0.5em} r{0.5em}){2-4} 
 \cmidrule[0.5pt](l{0.5em} r{0.5em}){5-7} 

&
\multicolumn{1}{c}{(1)} & 
\multicolumn{1}{c}{(2)} & 
\multicolumn{1}{c}{(3)} &
\multicolumn{1}{c}{(4)} & 
\multicolumn{1}{c}{(5)} & 
\multicolumn{1}{c}{(6)} \\

 \cmidrule[0.25pt](l{0.5em} r{0.5em}){1-7} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\addlinespace

\multicolumn{1}{l}{Bubble Dummy} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	reg_tmp <- r_dp_bubble_list[[i_reg]]
	coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1"),]
%>	
<%= cat("$", paste0(paste0(sprintf("%.3f", as.numeric( coef_tmp[["Estimate"]] ))), paste0("^{", star_builder(coef_tmp[["Estimate"]], coef_tmp[["Cluster s.e."]]), "}" )), "$") %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\
& 
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	reg_tmp <- r_dp_bubble_list[[i_reg]]
	coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1"),]
%>	
(<%= cat("$", sprintf("%.3f", as.numeric( coef_tmp[["Cluster s.e."]] ) ), "$") %>)
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\


\addlinespace

\multicolumn{1}{l}{Log Citations} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	if (i_reg %in% c(2,3,5,6)){
	reg_tmp <- r_dp_bubble_list[[i_reg]]
	coef_tmp <- summary(reg_tmp)[["coefficients"]][c(2),]
%>	
<%= cat("$", paste0(paste0(sprintf("%.3f", as.numeric( coef_tmp[["Estimate"]] ))), paste0("^{", star_builder(coef_tmp[["Estimate"]], coef_tmp[["Cluster s.e."]]), "}" )), "$") %>
<% } %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\
\multicolumn{1}{l}{\ (forward looking)} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	if (i_reg %in% c(2,3,5,6)){
	reg_tmp <- r_dp_bubble_list[[i_reg]]
	coef_tmp <- summary(reg_tmp)[["coefficients"]][c(2),]
%>	
(<%= cat("$", sprintf("%.3f", as.numeric( coef_tmp[["Cluster s.e."]] ) ), "$" )  %>)
<% } %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\


\addlinespace 
\multicolumn{1}{l}{Log Citations x bubble} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	if (i_reg %in% c(3,6)){
		reg_tmp <- r_dp_bubble_list[[i_reg]]
		if (i_reg %in% c(3)){
			coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1:log_N"),]
		} else if (i_reg %in% c(6)){
			coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1:log_Tcw"),]
		}
%>
<%= cat("$", paste0(paste0(sprintf("%.3f", as.numeric( coef_tmp[["Estimate"]] ))), paste0("^{", star_builder(coef_tmp[["Estimate"]], coef_tmp[["Cluster s.e."]]), "}" )), "$") %>
<% } %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\
\multicolumn{1}{l}{} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	if (i_reg %in% c(3,6)){
		reg_tmp <- r_dp_bubble_list[[i_reg]]
		if (i_reg %in% c(3)){
			coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1:log_N"),]
		} else if (i_reg %in% c(6)){
			coef_tmp <- summary(reg_tmp)[["coefficients"]][c("bubble1:log_Tcw"),]
		}
%>	
(<%= cat("$", sprintf("%.3f", as.numeric( coef_tmp[["Cluster s.e."]] ) ), "$" )  %>)
<% } %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\



% CONTROLS
\addlinespace
\addlinespace

\multicolumn{1}{l}{Fixed Effects} &
\multicolumn{1}{c}{Y, F} & \multicolumn{1}{c}{Y, F} & \multicolumn{1}{c}{Y, F} & 
\multicolumn{1}{c}{Y, F} & \multicolumn{1}{c}{Y, F} & \multicolumn{1}{c}{Y, F} 
\\


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addlinespace
\multicolumn{1}{l}{Observations} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	reg_tmp <- r_dp_bubble_list[[i_reg]]
%>	
\multicolumn{1}{c}{<%= prettyNum(reg_tmp[["N"]],big.mark=",",scientific=FALSE) %>}
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \addlinespace
\multicolumn{1}{l}{$R^2$} &
<% for (i_reg in seq(1, length(r_dp_bubble_list))){ 
	reg_tmp <- r_dp_bubble_list[[i_reg]]
%>	
<%=  %> 
<%= cat("$", sprintf("%.2f", as.numeric( summary(reg_tmp)[["r2"]] )), "$") %>
<%= paste0(ifelse(i_reg<6, "&", "")) %>
<% } %>
\\








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{comment}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \end{comment}



\bottomrule

\end{tabular*}
